package cn.sc.summer.calculate.condition;

import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.context.annotation.ConfigurationCondition;
import org.springframework.core.type.AnnotatedTypeMetadata;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.MethodMetadata;
import org.springframework.lang.NonNull;

/**
 * 类名：系统资源获取策略
 *
 * @author a-xin
 * @date 2024/9/20 13:09
 */
@Slf4j
public class SystemCondition implements ConfigurationCondition {

    /**
     * Determine if the condition matches.
     *
     * @param context  the condition context
     * @param metadata the metadata of the {@link AnnotationMetadata class}
     *                 or {@link MethodMetadata method} being checked
     * @return {@code true} if the condition matches and the component can be registered,
     * or {@code false} to veto the annotated component's registration
     */
    @Override
    public boolean matches(ConditionContext context, @NotNull AnnotatedTypeMetadata metadata) {
        Boolean enable = context.getEnvironment().getProperty("project.server.enable", Boolean.class, Boolean.FALSE);
        log.warn("=> The status of the system info engine: {}", enable);
        return enable;
    }

    /**
     * Return the {@link ConfigurationPhase} in which the condition should be evaluated.
     */
    @NonNull
    @Override
    public ConfigurationPhase getConfigurationPhase() {
        return ConfigurationPhase.REGISTER_BEAN;
    }

}
